﻿namespace CRM.DataAccess.DAOs
{
    using System.Collections.Generic;
    using System.Data.Entity;
    using CRM.DataAccess.Entities;
    using System.Linq;

    public class SalutationDAO : DbContext
    {
        public SalutationDAO()
            : base("name=Entities")
        {
        }
        public DbSet<SALUTATION> SALUTATIONS { get; set; }

        //Get All Lead Source
        public List<SALUTATION> GetAllSalutatioin()
        {
            try
            {
                var Query = from s in SALUTATIONS
                            select s;
                List<SALUTATION> sals = Query.ToList();
                if (sals.Count > 0)
                    return sals;
                return null;
            }
            catch
            {
                return null;
            }
        }
        //Add new Salutation
        public int AddNewSalutation(SALUTATION sal)
        {
            try
            {
                this.SALUTATIONS.Add(sal);
                this.SaveChanges();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        // get salutation by name
        public SALUTATION GetSalutationByName(string name)
        {
            try
            {
                var query = from s in SALUTATIONS
                            where s.SALUTATION_NAME.ToUpper() == name.ToUpper()
                            select s;
                List<SALUTATION> sals = query.ToList();
                if (sals.Count > 0)
                    return sals[0];
                return null;
            }
            catch
            {
                return null;
            }
        }
        
    }
}
